package com.zimmur.app.mocolink.background.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zimmur.app.mocolink.background.common.ReturnJsonEntity;
import com.zimmur.app.mocolink.background.common.StatusCodeEnum;
import com.zimmur.app.mocolink.domain.model.AppUser;
import com.zimmur.app.mocolink.domain.util.PageUtil;
import com.zimmur.app.mocolink.domain.vo.GroupGoodsInfo;
import com.zimmur.app.mocolink.domain.vo.TopicInfo;
import com.zimmur.app.mocolink.service.IAppUserService;
import com.zimmur.app.mocolink.service.IGroupGoodsService;
import com.zimmur.app.mocolink.service.IHomeService;
import com.zimmur.app.mocolink.service.ITopicService;

@RestController
@RequestMapping("/restful/home")
public class HomeController extends BaseController{

	@Autowired
	private IHomeService homeService;
	@Autowired
	private IGroupGoodsService groupGoodsService;
	@Autowired
	private ITopicService topicService;
	
	@RequestMapping("/buyIndex")
	public ReturnJsonEntity buyIndex(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		StatusCodeEnum codeEnum = StatusCodeEnum.CODE100000;
		Integer userId = getTokenUserId();
		Map<String, Object> map =homeService.buyIndex(userId);
		if(map!=null){
			entity.setData(map);
			codeEnum = StatusCodeEnum.CODE000000;
		}
		entity.init(codeEnum);
		return entity;
	}
	@RequestMapping("/queryGroupGoods")
	public ReturnJsonEntity queryGroupGoods(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		StatusCodeEnum codeEnum = StatusCodeEnum.CODE100000;
		Integer userId = getTokenUserId();
		Integer pageNo = getParam("pageNo", 1);
		PageUtil<GroupGoodsInfo> page = groupGoodsService.queryIndexGroupGoods(pageNo, userId);
		if(page!=null){
			entity.setData(page);
			codeEnum = StatusCodeEnum.CODE000000;
		}
		entity.init(codeEnum);
		return entity;
	}
	@RequestMapping("/findIndex")
	public ReturnJsonEntity findIndex(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		StatusCodeEnum codeEnum = StatusCodeEnum.CODE100000;
		Integer userId = getTokenUserId();
		Map<String, Object> map =homeService.findIndex(userId);
		if(map!=null){
			entity.setData(map);
			codeEnum = StatusCodeEnum.CODE000000;
		}
		entity.init(codeEnum);
		return entity;
	}
	@RequestMapping("/queryTopic")
	public ReturnJsonEntity queryTopic(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		StatusCodeEnum codeEnum = StatusCodeEnum.CODE100000;
		Integer pageNo = getParam("pageNo", 1);
		PageUtil<TopicInfo> page = topicService.queryTopicInfo(pageNo);
		if(page!=null){
			entity.setData(page);
			codeEnum = StatusCodeEnum.CODE000000;
		}
		entity.init(codeEnum);
		return entity;
	}
}
